package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;

public class HJ01_猜字谜 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/01.txt"));
        String[] mimian = in.nextLine().split(",");
        String[] midi = in.nextLine().split(",");
        boolean flag = false;
        for (String s1 : mimian) {
            for (String s2 : midi) {
                if (getMatch(s1, s2)) {
                    if (flag) {
                        System.out.print(",");
                    } else {
                        flag = true;
                    }
                    System.out.print(s2);
                }
            }
        }
        if (!flag) {
            System.out.println("not found");
        }
    }

    static boolean getMatch(String mimian, String midi) {
        Set<Character> set1 = new HashSet<>();
        Set<Character> set2 = new HashSet<>();
        for (char a : mimian.toCharArray()) {
            set1.add(a);
        }
        for (char a : midi.toCharArray()) {
            set2.add(a);
        }
        return set1.equals(set2);
    }
}
